<?php
namespace app\api\controller;

use think\facade\Config;
use think\facade\Request;
use think\Response;

abstract class Base
{
    protected $page;
    protected $pageSize;
    protected $title;
    protected $user_id;
    protected $token;

    public function __construct()
    {
        //获取页码相关参数
        $this->page = (int)Request::param('page');
        $this->title = (string)Request::param('title');
        $this->user_id = (int)Request::param('user_id');
        $this->token = (string)Request::header('Token');
        $this->pageSize = (int)Request::param('page_size', Config::get('app.page-size',10));

    }

    protected function create($data, string $msg = '', int $code = 200, string $type = 'json'):Response
    {
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Token");
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
        $data = [
            'code'      =>  $code,
            'msg'       =>  $msg,
            'data'      =>  $data
        ];
        return Response::create($data, $type);
    }

    public function __call($name, $arguments){
        return $this->create([], '资源不存在', 404);
    }

}